let gulp = require("gulp"); // gulp是一个实例对象;
let cleanCss = require("gulp-clean-css");
let rename = require("gulp-rename");
let concat = require("gulp-concat");
let babel = require("gulp-babel");
let uglify = require("gulp-uglify");
let dev = require("./gulp.dev");
let sass = require('gulp-sass');
sass.compiler = require('node-sass');

// 外置paths
let {
      paths
} = require("./gulp.config");

function styles() {
      return gulp.src(paths.styles.src)
            //  .pipe(concat("index.css"))
            .pipe(sass().on('error', sass.logError))
            .pipe(cleanCss())
            // .pipe(rename({
            //       suffix: '.min'
            // }))
            .pipe(gulp.dest(paths.styles.dist));
}

function scripts() {
      return gulp.src(paths.scripts.src)
            .pipe(concat("index.js"))
            // .pipe(babel({
            //       presets: ['@babel/env']
            // }))
            .pipe(uglify())
            .pipe(gulp.dest(paths.scripts.dist));
}

function html() {
      return gulp.src(paths.html.src)
            .pipe(gulp.dest(paths.html.dist));
}

function configs() {
      return gulp.src(paths.config.src)
            .pipe(uglify())
            .pipe(gulp.dest(paths.config.dist));
}

let build = gulp.series(html, styles, scripts, configs);
// console.log(dev);

exports.build = build;
exports.dev = dev;
exports.default = dev;